﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aij1.BLL;
using Aij1.Model;
using Aij1.Cms;
using Aij1.Utils;

namespace Aij1
{
    public partial class NewsCenter : BasePage
    {
        protected int CatId;
        protected WebPager WPager;
        protected void Page_Load(object sender, EventArgs e)
        {
            repNews.DataSource = ArticleData.GetPagedNewsList(WPager);
            repNews.DataBind();
            string pageName = WPager.PageIndex <= 1 ? "" : " 第" + WPager.PageIndex + "页"; 
            if (CatId <= 0)
            {
                PageName = "新闻中心" + pageName;
                Keywords = "摄影知识,爱+1动态,后期处理,摄影行业动态,育儿知识,儿童健康常识,怎样让宝宝更聪明";
                Description = Config.CompanyName + "收集和整理的与儿童摄影行业有关的知识文章和图集";
            }
            else
            {
                A_Category cat = XpoSession.GetObjectByKey<A_Category>(CatId);
                PageName = cat.Title + pageName;
                Keywords = cat.Intro;
                Description = cat.Intro;
            }
        }

        protected void Page_init(object sender, EventArgs e)
        {
            CatId = CommOp.ToInt(Request.QueryString["Id"]);
            CNM.CategoryId = CatId;
            CNM.CategoryType = ArticleType.新闻;

            WPager = new WebPagerSEO()
            {
                KeyId = "Oid",
                OrderBy = "SetTopTime DESC, DisplayTime DESC",
                Query = @"SELECT a.Oid,a.Title,a.DisplayTime,a.SetTopTime,a.Intro,a.AType,p.SnapShotUrl,p.SnapShotWidth,p.SnapShotHeight,c.Oid as CategoryId,c.Title as CategoryTitle,c.AType as CategoryType FROM 
A_Article a LEFT JOIN A_Photo p ON a.SamplePhotoId=p.Oid LEFT JOIN A_Category c ON A.CategoryId=c.Oid WHERE a.GCRecord IS NULL AND a.Status=3 AND " +
                (CatId == 0 ? "a.CategoryId IS NOT NULL AND c.AType=0" : "CategoryId=" + CatId),
                PageSize = 20,
            };
        }
    }
}